package structure.pattern.proxy;

import structure.pattern.proxy.dynamic_proxy.CarDynamicProxy;
import structure.pattern.proxy.help.BenzSell;
import structure.pattern.proxy.help.FordSell;
import structure.pattern.proxy.help.CarSell;
import structure.pattern.proxy.static_proxy.CarProxy;

import java.lang.reflect.Proxy;


/**
 * @Autor: yuanyongan
 * @Description:
 * @Date 2023/1/9 10:42
 */
public class Test {
    public static void main(String[] args) {
        // 静态代理
        CarProxy carProxy = new CarProxy();
        carProxy.fordSell();
        carProxy.benzSell();

        // 动态代理
        FordSell fordSell = new FordSell();
        BenzSell benzSell = new BenzSell();
        CarDynamicProxy<CarSell> fordDynamicProxy = new CarDynamicProxy<CarSell>(fordSell);
        CarDynamicProxy<CarSell> benzDynamicProxy = new CarDynamicProxy<CarSell>(benzSell);
        CarSell fordCarProxySell = (CarSell) Proxy.newProxyInstance(CarSell.class.getClassLoader(), new Class<?>[]{CarSell.class}, fordDynamicProxy);
        CarSell benzCarProxySell = (CarSell) Proxy.newProxyInstance(CarSell.class.getClassLoader(), new Class<?>[]{CarSell.class}, benzDynamicProxy);
        fordCarProxySell.sell();
        benzCarProxySell.sell();
    }
}
